from datetime import datetime

from cyds import db


class BaseModel(object):
    """模型基类"""
    create_time = db.Column(db.DateTime, default=datetime.now)
    update_time = db.Column(db.DateTime, default=datetime.now, update_time=datetime.now)


class News(BaseModel, db.Model):
    """新闻模型"""
    __tablename__ = "news"

    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(256), nullable=False)
    content = db.Column(db.Text, nullable=False)
    image_url = db.Column(db.String(256))


class Category(BaseModel, db.Model):
    """小组分类(学校)"""
    __tablename__ = "category"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(256), nullable=False)


class Squad(BaseModel, db.Model):
    """小组作品模型"""
    __tablename__ = "squad"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(256), nullable=False)
    video_url = db.Column(db.String(256), nullable=False)
    school = db.Column(db.Integer, db.ForeignKey('category.id'))
    profession = db.Column(db.String(256), nullable=False)
    grade = db.Column(db.String(256), nullable=False)


class User(BaseModel, db.Model):
    """管理员用户"""
    __tablename__ = "user"

    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(256), nullable=False)
    password = db.Column(db.String(256), nullable=False)


class Applicant(BaseModel, db.Model):
    """报名的小组"""
    __tablename__ = "applicant"

    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(256), nullable=False)
    school = db.Column(db.String(256), nullable=False)
    profession = db.Column(db.String(256), nullable=False)
    grade = db.Column(db.String(256), nullable=False)

